package com.credithc.eagleeye.spring.starter;
import com.credithc.eagleeye.agent.IEagleEyeAgent;
import com.credithc.eagleeye.agent.factory.EagleEyeAgentFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * 描 述: <br/>
 * 作 者: zhangjin<br/>
 * 创 建：2018年09月22日<br/>
 * 版 本：v1.0.0<br>
 * <p>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
@Configuration
@EnableConfigurationProperties(EagleEyeProperties.class)
public class EagleEyeAgentAutoConfiguration   {
    @Autowired
    private EagleEyeProperties eagleEyeProperties;

    @Bean
    @ConditionalOnMissingBean(IEagleEyeAgent.class)
    public IEagleEyeAgent eagleEyeAgent() {
        IEagleEyeAgent eagleEyeAgent = EagleEyeAgentFactory.getInstance();
        if (eagleEyeAgent == null) {
            eagleEyeAgent=EagleEyeAgentInitializer.startEagleEye(eagleEyeProperties);
        }
        return eagleEyeAgent;
    }

}
